package org.genew.squadra.xml.presentation;

import org.genew.squadra.xml.common.ValidationUtility;
import org.genew.squadra.xml.model.MyMultipleFileFourForm;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.stereotype.Component;
@Component
public class XmlValidator implements Validator {
	@Override
	public boolean supports(Class<?> klass) {
		// TODO Auto-generated method stub
		return MyMultipleFileFourForm.class.isAssignableFrom(klass);
	}

	@Override
	public void validate(Object target, Errors error) {
	
		
		MyMultipleFileFourForm myform = (MyMultipleFileFourForm) target; 
		
		ValidationUtility.rejectIfNoWellFermed(error, "errors.nowell", myform.getCommonsMultipartFilesXHTML(), "commonsMultipartFilesXHTML");
		ValidationUtility.rejectIfNoWellFermed(error, "errors.nowell", myform.getCommonsMultipartFilesIntroduzione(), "commonsMultipartFilesIntroduzione");
		ValidationUtility.rejectIfNoWellFermed(error, "errors.nowell", myform.getCommonsMultipartFilesPrefazione(), "commonsMultipartFilesPrefazione");
		//ValidationUtility.rejectIfNoWellFermed(error, "errors.nowell", myform.getCommonsMultipartFilesGuide());
		ValidationUtility.rejectIfNoExt(error, "errors.extension", myform.getCommonsMultipartFilesXHTML(), "xhtml", "commonsMultipartFilesXHTML");
		ValidationUtility.rejectIfNoExt(error, "errors.extension", myform.getCommonsMultipartFilesIntroduzione(), "xhtml", "commonsMultipartFilesIntroduzione");
		//ValidationUtility.rejectIfNoExt(error, "errors.extension", myform.getCommonsMultipartFilesGuide(), "xhtml", "");
		ValidationUtility.rejectIfNoExt(error, "errors.extension", myform.getCommonsMultipartFilesPrefazione(), "xhtml", "commonsMultipartFilesPrefazione");
		
	}

}
